<?php
/*
 * [JINYUN!] (C)2001-2099 Jinyunweb.com
 * This is NOT a freeware, use is subject to license terms
 *供货商对账
*/
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'list';
$return=array();
$tabs=array(
);
//供货商对账
if($_RQ['op']=='list'){
	$params=array();
	$params['uniacid']=$_SESSION['uniacid'];
	$params['ispay']=1;
	$params['userid >']=0;
	if(!empty($_RQ['name'])){
		$params['name like']='%'.trim($_RQ['name']).'%';
		$return['params']['name']=$_RQ['name'];
	}
	if(!empty($_RQ['mobile'])){
		$params['mobile']=trim($_RQ['mobile']);
		$return['params']['mobile']=$_RQ['mobile'];
	}
	if(!empty($_RQ['order'])){
		$params['order']=trim($_RQ['order']);
		$return['params']['order']=$_RQ['order'];
	}
	//创建时间
	if($_RQ['createtime']){
		$time_range=cfc('tools')->base64_decode($_RQ['createtime'],$_SESSION['base_key_str']);
		$time_range=json_decode($time_range,true);
		$params['createtime between']=array($time_range['tstart'],$time_range['tend']);
		$return['params']['createtime']=$time_range;
	}
	$pindex = max(1, intval($_RQ['page']));
	$psize = 10;
	$total='';
	 $fields=array('id','order','name','mobile','ispay','fee','mid','createtime','status','userid');
	$list=pdo_getslice('jy_jd_order',$params,array($pindex,$psize),$total,$fields,'','id desc');
	if($list){
		foreach($list as &$item){
			$item['member']=cfc('core')->member_show($item['mid']);
			$merch=pdo_get('jy_jd_user',array('uniacid'=>$_SESSION['uniacid'],'id'=>$item['userid']));
			$item['merchtitle']=$merch['merchname']?:'无';
			$item['merchimg']=$merch['logo'];
		}
	}
	
	$return['list']=$list;
	$totalpage=ceil($total/$psize);
	$totalpage=intval($totalpage);
	$return['totalpage'] =$totalpage;
	$return['params']['page'] =$pindex;
	$htmls=array(
		'type'=>'list',
		'export'=>'export',
		'tabs'=>$tabs,
		'list'=>array('data'=>'list','edit'=>false,'del_one'=>false,'delall'=>false,'list'=>array(
			array('name'=>'order','title'=>'单号','type'=>'string'),
			array('name'=>'member','title'=>'会员信息_Member','type'=>'member'),
			array('name'=>'name','title'=>'用户名称','type'=>'string'),
			array('name'=>'mobile','title'=>'用户电话','type'=>'string'),
			array('type'=>'img_string','title'=>'商户信息','img'=>'merchimg',
			'data'=>array(
				array('title'=>'ID：','name'=>'userid'),
				array('title'=>'名称：','name'=>'merchtitle')
				)
			),
			array('name'=>'fee','title'=>'金额','type'=>'string'),
			array('name'=>'createtime','title'=>'下单时间','type'=>'time'),
			array('name'=>'status','title'=>'订单状态','type'=>'radio','options'=>'order_status'),
		)),
		'search'=>array(
			array('name'=>'order','width'=>15,'title'=>'单号','type'=>'string'),
			array('name'=>'name','width'=>15,'title'=>'姓名','type'=>'string'),
			array('name'=>'mobile','width'=>15,'title'=>'手机号','type'=>'string'),
			array('name'=>'createtime','width'=>15,'title'=>'时间','type'=>'time_range'),
		)
	);
	$return['order_status']=$this->order_status;
	$return['htmls']=$htmls;
	exi($return);
}
if($_RQ['op']=='export'){
	$params=array();
	$params['uniacid']=$_SESSION['uniacid'];
	if(!empty($_RQ['name'])){
		$params['name like']='%'.trim($_RQ['name']).'%';
		$return['params']['name']=$_RQ['name'];
	}
	if(!empty($_RQ['order'])){
		$params['order']=trim($_RQ['order']);
		$return['params']['order']=$_RQ['order'];
	}
	//创建时间
	if($_RQ['createtime']){
		$time_range=cfc('tools')->base64_decode($_RQ['createtime'],$_SESSION['base_key_str']);
		$time_range=json_decode($time_range,true);
		$params['createtime between']=array($time_range['tstart'],$time_range['tend']);
	}
	$list=pdo_getall('jy_jd_order',$params);
	if($list){
		foreach($list as &$item){
			$member=pdo_get('core_members',array('uniacid'=>$_SESSION['uniacid'],'id'=>$item['mid']));
			$item['nickname']=$member['nickname'];
			$item['avatar']=$member['avatar'];
			$item['createtime']=date('Y-m-d H:i:s',$item['createtime']);
			$item['status']=$this->order_status[$item['status']];
			$merch=pdo_get('jy_jd_user',array('uniacid'=>$_SESSION['uniacid'],'id'=>$item['userid']));
			$item['merchtitle']=$merch['merchname']?:'无';
		}
	}
	$header=array(
		'order'=>'单号',
		'nickname'=>'用户昵称',
		'name'=>'用户姓名',
		'mobile'=>'用户电话',
		'merchtitle'=>'商户信息',
		'fee'=>'金额',
		'status'=>'订单状态',
		'createtime'=>'时间',
	);
	cfc('tools')->export2excel($header,$list,'商户日志');
}
if($_RQ['op']=='del'){
	$del=trim($_RQ['del'],';');
	if($del){
		$del=explode(';',$del);
	}else{
		$del=array();
	}
	if($_RQ['id']){
		$del[]=$_RQ['id'];
	}
	foreach($del as $id){
		$id=intval($id);
		if($id){
			pdo_delete('jy_jd_order',array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
		}
	}
	exi('删除成功！');
}